<?php if (!defined('BASEPATH'))  exit('No direct script access allowed');
/**
 * @filesource user_grid.php
 */
if(0){?><script><?php }?>

Ext.define('Hydcrm.user.UserQuitGrid', {
    extend: 'Ext.grid.Panel',
    
    requires: [
        'Ext.grid.*'
    ],
    xtype: 'grid',
    id: 'user_quit_tab',
    frame: true,
    title: '离职管理',
    closable: false,
    //closeAction: 'hide',
    autoScroll: true,
    store: list_user_quit_ds,
    bodyPadding: 1,
    tbar: [
        '->',
        Ext.create('Ext.form.TextField', {
            name: 'search',
            width: 100,
            listeners:{
                render: function (field, p) {
                    Ext.QuickTips.init();
                    Ext.QuickTips.register({
                          target: field.el,
                          text: '登录用户名，姓名'
                    });
                 },
                specialKey : function(field, e) {  
                    if (e.getKey() == Ext.EventObject.ENTER) { //响应回车  
                        onsearchUser();
                    }  
                }
            }
        }),
        {
            iconCls: 'icon-search',
            text: '搜索',
            handler: function(){ 
                onsearchUser(); 
            },
            //tooltip: HydcrmLanguage.btnSearch,
            scope: this
        }], 

    initComponent: function(){
        this.width =  '100%';
        //员工ID，员工编码， 角色，登录名，姓名，部门，团队名称，操作       
        this.columns = [{
            text: '员工ID',
            hidden: true,
            sortable: false,
            dataIndex: 'id'
        },{
            text: '部门ID',
            hidden: true,
            sortable: false,
            dataIndex: 'departmentid'
        },{
            text: '团队ID',
            hidden: true,
            sortable: false,
            dataIndex: 'teamid'
        },{
            text: '员工编码',
            width: 120,
            sortable: true,
            dataIndex: 'worknum'
        }, {
            text: '登录用户名',
            width: 120,
            sortable: true,
            dataIndex: 'tel'
        }, {
            text: '姓名',
            width: 120,
            sortable: true,
            dataIndex: 'name'
        },{
            text: '角色',
            width: 100,
            sortable: true,
            dataIndex: 'level',
            renderer: this.renderLevel
        }, {
            text: '部门',
            width: 180,
            sortable: true,
            dataIndex: 'department_name'
        }, {
            text: '团队名称',
            flex: 1,
            sortable: true,
            dataIndex: 'team_name'
        }, {
            text: '状态',
            width: 150,
            sortable: true,
            dataIndex: 'status',
            renderer: this.renderStatus
        }, {xtype: 'actioncolumn',align: 'center',
                width: 150,
                header: '操作',
                items: [{
                    //iconCls: 'icon-quit',
                    text: '离职',
                    tooltip: '离职',
                    handler: function(grid, rowIndex, colIndex) {//alert('修改' + rowIndex + colIndex);
                        var rec = grid.getStore().getAt(rowIndex); 
                        Ext.Msg.show({
                            title:'确认离职?',
                            msg: '你确定将：('+rec.get('name')+') 置为离职状态?',
                            buttons: Ext.Msg.YESNOCANCEL,
                            icon: Ext.Msg.QUESTION,
                            fn: function(btn) {
                                if (btn === 'yes') {
                                    Ext.Ajax.request({
                                        url: Hydcrm.CONF.CONN_URL,
                                        params: {
                                            module: 'user',
                                            controller: 'user',
                                            action: 'quit_user',
                                            id: rec.get('id')
                                        },
                                        callback: function(options, success, response) {
                                            if(response.responseText){
                                                var result = Ext.decode(response.responseText);
                                                if (result.success == true) { //fireEvent('notifysuccess', result.feedback); //this.close();
                                                    //Ext.MessageBox.alert(HydcrmLanguage.msgSuccessTitle, result.feedback);
                                                    Ext.MessageBox.alert('提示信息', result.feedback);
                                                } else {
                                                    Ext.MessageBox.alert(HydcrmLanguage.msgErrTitle, result.feedback);
                                                }
                                            }
                                        },
                                        scope: this
                                    });
                                } else if (btn === 'no') {//console.log('No pressed');
                                } else {//console.log('Cancel pressed');
                                    
                                } 
                            }
                        });
                    },
                    scope: this
                }]
        }];

        this.bbar = Ext.create('Ext.PagingToolbar', {
            store: list_user_quit_ds,
            displayInfo: true,
            displayMsg: '显示条目 {0} - {1} of {2}',
            emptyMsg: "无信息可显示",
            inputItemWidth: 35,
            items:['-']
        });
        this.callParent();
    },
    renderStatus: function(val){ //alert(val);
        switch (val) {
            case 'Q1':
                return '待审批';
            case 'Q2':
                return '审批驳回';
            case 'Q3':
                return '审批通过';
        }
    },
    renderLevel: function(val){ //alert(val);
        switch (val) {
            case '0':
                return '员工';
            case '1':
                return '主管';
            case '2':
                return '经理';    
        }
    }
});